package cn.com.chengmandian.bike.service.impl;

import cn.com.chengmandian.bike.dto.RemindRuleDto;
import cn.com.chengmandian.bike.mapper.EbRemindRuleMapper;
import cn.com.chengmandian.bike.model.EbRemindRule;
import cn.com.chengmandian.bike.service.IEbRemindRuleService;
import cn.com.chengmandian.core.common.constants.CommonConstant;
import cn.com.chengmandian.core.web.pojo.AgentInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 电单车运营-会员提醒-提醒规则 服务实现类
 * </p>
 *
 * @author AutoGenerator
 * @since 2024-07-03
 */
@Service
public class EbRemindRuleServiceImpl extends ServiceImpl<EbRemindRuleMapper, EbRemindRule> implements IEbRemindRuleService {

    @Override
    public List<EbRemindRule> list(RemindRuleDto dto) {
        return this.list(
                new LambdaQueryWrapper<EbRemindRule>()
                        .in(EbRemindRule::getType, dto.getTypes())
                        .isNotNull(EbRemindRule::getWxMiniTemplete)
        );
    }

    @Override
    public EbRemindRule getNotifyRule(Integer agentId, Integer type) {
        return this.getOne(
                new LambdaQueryWrapper<EbRemindRule>()
                        .eq(EbRemindRule::getAgentId, agentId)
                        .eq(EbRemindRule::getType, type)
                        .orderByDesc(EbRemindRule::getId)
                        .last("limit 1")
        );
    }
}
